package systemConfigService

import (
	"arabApi/app/api/models/systemConfigModel"
	"arabApi/app/api/requests/systemConfigRequest"
	"arabApi/app/api/services/CService"
	"arabApi/app/api/services/LoginService"
	"arabApi/pkg/helpers"
	"github.com/spf13/cast"
)

func List(req systemConfigRequest.SystemConfigRequest) ([]interface{}, int64) {

	list, count := systemConfigModel.List(req)

	list1 := make([]interface{}, len(list))
	userList := LoginService.UserListGetFiled("id", "name")
	for key, item := range list {
		item1 := helpers.S_struct_to_map(item)
		item1["stateName"] = CService.State_kai_guan[item.State]
		item1["opName"] = userList[cast.ToString(item1["operator"])]
		delete(item1, "operator")
		list1[key] = item1
	}

	return list1, count
}

func GetMsgById(id int64) interface{} {
	msg := systemConfigModel.GetMsgById(id)
	mapmsg := helpers.S_struct_to_map(msg)
	return mapmsg
}

func ListCount() int64 {
	return systemConfigModel.ListCount()
}

func Add(add systemConfigRequest.SysAdd) uint64 {
	return systemConfigModel.Add(add)
}

func Update(add systemConfigRequest.SysAdd) error {
	return systemConfigModel.Update(add)
}

func Del(id int64) error {
	return systemConfigModel.Del(id)
}
